home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / misc / vpan100.zip / VPBASE.H < prev    next >
C/C++ Source or Header  |  1995-01-12  |  9KB  |  290 lines

  1. //
  2. //  VIRTUAL PANELS * GRAPHIC USER UNTERFACE FOR LABORATORY WORKS
  3. //
  4. //    VPBASE.H : common def & functions,
  5. //           base classes: plaque,display,object
  6. //
  7. //
  8. //                       |     Written by O.Rasizade
  9. //    declarations       |       Sept 1992,1993
  10. //                       |
  11. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12.  
  13. #ifndef __cplusplus
  14. #error Must use C++
  15. #endif
  16.  
  17. #ifndef __VPBASE_H
  18. #define __VPBASE_H
  19.  
  20.  
  21. #define CLIP_ON  1        /* activates clipping in viewport */
  22. #define CLIP_OFF 0        /* deactivates clipping in viewport */
  23.  
  24. #define FRAMED   1        // to draw frame around display or not
  25. #define UNFRAMED 0
  26.  
  27. #define ON  1
  28. #define OFF 0
  29.  
  30. #define     SPACING    3    // for vert. text.
  31. #define  SHADWIDTH    2    // for plaque.
  32. #define  BOXFRWD    2    // width of frame of IN,OUT text boxes
  33.  
  34. #define  VERT    1        // for butgr direction of buttons row
  35. #define  HORIZ  0
  36.  
  37. #define  EGAVGA 1    //for InitGraphMode, forces to link VGA driver
  38.             //into exe file
  39. #define CNFG_FILE_KEY  "LABGUI_CNF" // key to define config file.
  40.                     // must be at start of file with term. 0
  41. #define KEYLEN        11          // length of keyword with term. 0
  42.  
  43.     //------------- STATUS OF CONTROLS ------
  44.  
  45. #define    CRL_ACTIVE    2    // hihglighted
  46. #define CRL_ENABLED     1
  47. #define CRL_DISABLED    0       // grayed
  48. #define CRL_HLDISABLED  3       // hihglight grayed
  49.  
  50.     //--------- STATUS OF CONSOLE (ConStatus flags) -----
  51.  
  52. #define  KBD_HIT    1
  53. #define  KBD_CLRHIT    0xFFFE
  54.  
  55.     //-------------- Global variables --------------
  56. extern int maxx,maxy,maxxx,maxyy;    //max and min of screen
  57. extern int x0s,y0s,xmaxs,ymaxs;        // size and
  58. extern int xx0s,yy0s,xxmaxs,yymaxs;
  59. extern int fillptrn,fillcolor;        // fill style of object drag area
  60. extern float xas,yas;            // aspect ratios
  61. extern int xxspacing,yyspacing;        // versatile spacing between text lines
  62.  
  63. extern int menustatus;        // status of menu system:
  64.                 //   if 0 then menu system is not installed
  65.                 //      1 then menu system has been installed
  66.  
  67.      //----------------------------------------------
  68.  
  69. #define max(a,b)    (((a) > (b)) ? (a) : (b))
  70. #define  round(V)      (((V)>=0)?((V)+.5):((V)-.5))
  71.  
  72. #define  maxviewport     setviewport(0,0,maxxx,maxyy,CLIP_ON)
  73. #define beep           putch(7)
  74.  
  75. void far lgErrExit(char *msg);
  76. inline void far procDummy(void) {}
  77. inline void far procNULL(void) { lgErrExit("procNULL:Illegal object proc call");}
  78.  
  79.     // object types:fixed       no list  no drag
  80.     //        permanent    list     drag
  81.     //        popup     no list     drag
  82. enum objtype {FIXED,PERM,POPUP};
  83.  
  84.  
  85. //+++++++++++ LABGUI FUNCTIONS ++++++++++++
  86.  
  87. void  InitAndCopyright
  88.             (char *copyright,
  89.             int fillcolor=MAGENTA,int fillptrn=CLOSE_DOT_FILL,
  90.             int grdrv=0, char *bgipath="..\\bgi");
  91. void  QuitVirtualPanels(void); // restore preceding CRT
  92. //--------------------------- Implementation in VPCOPYRT.CPP module
  93. void  InitVirtualPanels(int _x0s=0,int _y0s=0,int _xmaxs=0,int _ymaxs=0,
  94.             int _fillcolor=MAGENTA,int _fillptrn=CLOSE_DOT_FILL);
  95.     // if _xmaxs(_ymaxs) is 0 then dragging region is set to whole screen
  96.  
  97. //------------------------------------------------------------
  98. // transforms length in pixels in accordance with aspect ratio
  99. //------------------------------------------------------------
  100. int   xx__x(int xpix);    //x to aspect x
  101. int   yy__y(int ypix);
  102. int   x__xx(int xpix);    //aspect x to x
  103. int   y__yy(int ypix);
  104.  
  105. //-------------------------------------------------------------
  106. //             set Dragging Area
  107. //-------------------------------------------------------------
  108.  
  109. void  SetDragAreaX0( int x0);
  110. void  SetDragAreaY0( int y0);
  111. void  SetDragAreaXmax( int xmax);
  112. void  SetDragAreaYmax( int ymax);
  113.  
  114. //+++++++++++ General Purpose Functions ++++++++++++
  115.  
  116. #ifdef __cplusplus
  117. extern "C" {
  118. #endif
  119. void  InitGraphMode(int grdrv=0,char *bgipath="..\\bgi");
  120. int  gprintf( int xloc, int yloc, char *fmt, ... );
  121. int  gprintf_n( int *xloc, int *yloc, char *fmt, ... );
  122. int  WidthOfTemplate(char *format,...);
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126.  
  127. //----------------------------------------------------
  128. //             CLASSES
  129. //----------------------------------------------------
  130.  
  131. //++++++++++++++ CLASS   << PLAQUE >>  +++++++++++++++
  132.  
  133. struct plaquecolors
  134.     {COLORS
  135.     surface ,
  136.     shadow ,
  137.     ltnd;
  138.     };
  139. const plaquecolors plaquecoldflt={
  140.              LIGHTGRAY,    // surface
  141.              DARKGRAY,    // shadow
  142.              WHITE    // ltnd
  143.             };
  144. class plaque
  145. {
  146.  protected:
  147.     plaquecolors plqcolors;
  148.     int xxlen,yylen;    // versatile size
  149.  
  150.  public:
  151.     // Constructors
  152.    plaque (plaquecolors plaquecolconfig=plaquecoldflt)
  153.                  { plqcolors=plaquecolconfig;}
  154.    plaque (int xlength,int ylength,
  155.             plaquecolors plaquecolconfig=plaquecoldflt)
  156.           {
  157.            xxlen=xx__x(xlength); yylen=yy__y(ylength);
  158.            plqcolors=plaquecolconfig;
  159.            }
  160.  virtual void   PaintAt(int x0,int y0);//Draws plaque on the screen
  161. };//--------------- END of class PLAQE ------------------
  162.  
  163. //+++++++++++++++++++++++++++++++++++++++++++++++++++++
  164. //++++++++++++++ CLASS   << DISPLAY >>  +++++++++++++++
  165. //+++++++++++++++++++++++++++++++++++++++++++++++++++++
  166.  
  167. // Note that display may be created on the plaque, so
  168. // it uses plaques colors
  169.  
  170. // Default
  171. const COLORS dispcoldflt= BLACK;
  172.  
  173. class display : public plaque
  174. {
  175.   void  swapcolors(COLORS dispcolconfig)
  176.        {
  177.     COLORS temp;
  178.     temp=plqcolors.shadow; plqcolors.shadow=plqcolors.ltnd;
  179.     plqcolors.ltnd=temp; plqcolors.surface=dispcolconfig;
  180.        }
  181.  protected:
  182.  
  183.   int xx0p,yy0p,xxmaxp,yymaxp;    // viewport of display "paper"
  184.   int xx0pd,yy0pd;              // origin of "paper" relative to frame
  185.   int frame;            // boolean: 0-no frame should be painted
  186.  
  187.   //-------------------------- Constructors --
  188.     display (int _frame=FRAMED,plaquecolors plaquecolconfig=plaquecoldflt,
  189.            COLORS dispcolconfig=dispcoldflt) :
  190.             plaque(plaquecolconfig)
  191.  
  192.             { swapcolors(dispcolconfig);frame=_frame;}
  193.  
  194.     display (int xlen,int ylen,int _frame=FRAMED,
  195.            plaquecolors plaquecolconfig=plaquecoldflt,
  196.                 COLORS dispcolconfig=dispcoldflt) :
  197.             plaque(xlen,ylen,plaquecolconfig)
  198.     {swapcolors(dispcolconfig);frame=_frame;}
  199.  
  200.  virtual void  PaintAt(int x0,int y0);
  201.  
  202. public:
  203.  virtual    void  cls();
  204.  
  205. };//++++++++++++++ END of class DISPLAY +++++++++++++++++++++
  206.  
  207. //++++++++++++++++++++++++++++++++++++++++++++++++++++
  208. //++++++++++++++ CLASS   << OBJECT >>  +++++++++++++++
  209. //++++++++++++++++++++++++++++++++++++++++++++++++++++
  210.  
  211. class object
  212. {
  213.  friend butsystem;
  214.  
  215.     int handle;
  216.     void far *savebuf;    // ptr to underlying image storage
  217.  
  218.  static void  XorRect(void);
  219.  
  220. protected:
  221.     // Stack of Objects : list of POPUP and on the screen PERM objects
  222.  static object  *actobj;    // ptr to active object-top of list
  223.  static object  *btmobj;    // ptr to first object-bottom of list
  224.     // connected list of all Objects
  225.  static object  *fstobj;    // ptr to first  object
  226.  static object  *lastobj;    // ptr to last object
  227.  
  228.   char *title;
  229.   int  titlefont,titlefontsize;
  230.         // STATUS of object
  231.  
  232.  
  233.   objtype type;        // may be FIXED,PERM,POPUP
  234.   void (far *proc)(void);    //paint procedure
  235.           // ptrs for the Stack of Objects - list of POPUP and
  236.           //                on the screen PERM objects
  237.   object *prev,*next;
  238.          // ptrs for the List of all Objects
  239.   object *prevobj,*nextobj;
  240.  
  241. // Protected METHODS
  242.  static object *  GetObject( int _handle);
  243.     // returns ptr ot object class if OK
  244.     //         or NULL if there is no object with _handle
  245.     void  Save(void); //save underlying image
  246.  static void  Drag(void);
  247.  static void  Delete(void);
  248.  
  249.  
  250. public:
  251.     int x0,y0,xmax,ymax;    // location of object
  252.     int xx0,yy0,xxmax,yymax;// versatile location of object
  253.     unsigned OnScreen;
  254.     unsigned Active;
  255.  
  256.     // Constructor
  257.    object(int _x0,int _y0,
  258.         objtype _type,char *_title,
  259.         void (far *_proc)(),int _titlefont,int _titlefontsize);
  260.     // Destructor
  261.    ~object(void);
  262.  
  263. static  void  RepaintScr(void);
  264. static  void  NextPERM(void);
  265. virtual void  Paint(void)=0; // paint object
  266. virtual    void  MovetoXY(int _x0,int _y0);
  267.     void  GetXY(int *_x0,int *_y0,int *_xmax,int *_ymax)
  268.         {*_x0=x0;*_y0=y0;*_xmax=xmax;*_ymax=ymax;}
  269.     void  GetXXYY(int *_xx0,int *_yy0,int *_xxmax,int *_yymax)
  270.         {*_xx0=xx0;*_yy0=yy0;*_xxmax=xxmax;*_yymax=yymax;}
  271.     void  Remove(void); //remove POPUP object from screen
  272.                   //and restore underlying image
  273.     void  MkActive(void);      //move obj on top of list
  274.  
  275.  static int   LoadCnfg(char *name);//Load PERM or POPUP objs last configuration
  276. /* returns:
  277.  *     0 if OK,
  278.  *    -1 if   name file doesn't exist
  279.  *    -2    or no PERM or POPUP objects currently exit
  280.  *    -3    or keyword doesn't match
  281.  */
  282.  static int   SaveCnfg(char *name);//Save PERM or POPUP objs last configuration ------
  283. // returns:
  284. //     0 if OK,
  285. //    -1 if cannot write to or create configuration file
  286. //    -2 if no PERM or POPUP objects currently exit
  287. };
  288. //--------------- END of class OBJECT ------------------
  289.  
  290. #endif // __VPBASE_H